package com.wowo.util;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MyBatisUtil {
    private static SqlSessionFactory sqlSessionFactory = null;
    public static SqlSessionFactory getSqlSessionFactory() throws IOException {
        if (sqlSessionFactory == null){
            Reader reader = Resources.getResourceAsReader("mybatis_conf.xml");
            return new SqlSessionFactoryBuilder().build(reader);
        }
        return sqlSessionFactory;
    }

//    public static SqlSessionFactory getSqlSessionFactory() throws IOException {
//        //获得SqlSessionFactory对象
//        Reader reader = Resources.getResourceAsReader("conf.xml");
//        SqlSessionFactory sqlSessionFactory =
//                new SqlSessionFactoryBuilder().build(reader);
//        return sqlSessionFactory;
//    }
    public static void main(String[] args) throws IOException {
        //获得SqlSessionFactory对象
        //Reader reader = Resources.getResourceAsReader("mybatis_conf.xml");
        //SqlSessionFactory sqlSessionFactory =
           //     new SqlSessionFactoryBuilder().build(reader);
        System.out.println(getSqlSessionFactory());
    }
}